---
title: "Table A.12"
output: 
---

# Table A.12

# Who's to Blame? Postconflict Violence and Public Attitudes Towards Peace Agreements
# Wyer, Frank. 

#clear environment
```{r clear environment}
rm(list = ls())
```

# uncomment and set working directory to replication archive
# setwd("~/blame_replication")

# Uncomment to install packages if necessary
# install.packages("tidyverse")
# install.packages("estimatr")
# install.packages("fabricatr")
# install.packages("texreg")

#load packages
```{r}
library(tidyverse)
library(estimatr)
library(fabricatr)
library(texreg)
```

#read in data
```{r}
survey_clean <- read.csv("survey_clean.csv")
intensity_data <- read.csv("Raw Data Files/intensity_data.csv")
displace_data <- read.csv("Raw Data Files/displace_data.csv")
```

#merge data on conflict displacement and intensity to survey data
```{r}
survey_clean <- left_join(survey_clean, intensity_data, by = "municode")
survey_clean <- left_join(survey_clean, displace_data, by = "municode")
```

#split municipalities into categories based on displacement variable
```{r displacement categorical variable}
survey_clean <- survey_clean %>% mutate(displace_pre_hilo = as.factor(split_quantile(displace_rate_pre, 2)))
survey_clean <- survey_clean %>% mutate(displace_post_hilo = as.factor(split_quantile(displace_rate_post, 2)))
```
 
#split municipalities into categories based on conflict intensity variable
```{r intensity categorical variable}
survey_clean <- survey_clean %>% mutate(victims_post_hilo = as.factor(split_quantile(victims_rate_post, 2)), victims_pre_hilo = as.factor(split_quantile(victims_rate_pre, 2)))
```

#estimate models for exploratory conflict exposure measures with and without controls, among control group respondents
```{r estimate models}
disp_hi_pre <- lm_robust(outcomes_zscale ~ factor(displace_pre_hilo == 2), survey_clean %>% filter(treatment == "C"))
disp_hi_pre_controls <- lm_robust(outcomes_zscale ~ factor(displace_pre_hilo == 2) + Q15 + Q25 + urbandummy + engage_zscale + factor(regionname), survey_clean %>% filter(treatment == "C"))

disp_hi_post <- lm_robust(outcomes_zscale ~ factor(displace_post_hilo == 2), survey_clean %>% filter(treatment == "C"))
disp_hi_post_controls <- lm_robust(outcomes_zscale ~ factor(displace_post_hilo == 2) + Q15 + Q25 + urbandummy + engage_zscale + factor(regionname), survey_clean %>% filter(treatment == "C"))

intens_hi_pre <- lm_robust(outcomes_zscale ~ factor(victims_pre_hilo == 2), survey_clean %>% filter(treatment == "C"))
intens_hi_pre_controls <- lm_robust(outcomes_zscale ~ factor(victims_pre_hilo == 2) + Q15 + Q25 + urbandummy + engage_zscale + factor(regionname), survey_clean %>% filter(treatment == "C"))

intens_hi_post <- lm_robust(outcomes_zscale ~ factor(victims_post_hilo == 2), survey_clean %>%
filter(treatment == "C"))
intens_hi_post_controls <- lm_robust(outcomes_zscale ~ factor(victims_post_hilo == 2) + Q15 + Q25 + urbandummy + engage_zscale + factor(regionname), survey_clean %>% filter(treatment == "C"))
```

#table - Heterogeneity in Control Group: Alternative Conflict Exposure Measures
```{r conflict exposure table}
texreg(list(disp_hi_pre, disp_hi_pre_controls, disp_hi_post, disp_hi_post_controls, intens_hi_pre, intens_hi_pre_controls, intens_hi_post, intens_hi_post_controls), custom.coef.map = list("(Intercept)" = "(Intercept)", "factor(displace_pre_hilo == 2)TRUE" = "High Displacement Pre-2016", "factor(displace_post_hilo == 2)TRUE" = "High Displacement Post-2016", "factor(victims_pre_hilo == 2)TRUE" = "High Conflict Intensity Pre-2016", "factor(victims_post_hilo == 2)TRUE" = "High Conflict Intensity Post-2016"), digits = 2, include.ci = FALSE, single.row = FALSE, include.fstatistic = FALSE, include.rmse = FALSE, include.rsquared = FALSE, include.adjrs = FALSE, include.nobs = TRUE, stars = numeric(0), custom.gof.rows = list("Controls" = c("", "\\checkmark", "", "\\checkmark", "", "\\checkmark", "", "\\checkmark")), float.pos = "h", caption.above	= TRUE, caption = "Heterogeneity in Control Group: Alternative Conflict Exposure Measures")
```


